package com.unione.heathrobot

import android.util.Log
import com.blankj.utilcode.util.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import okhttp3.internal.wait
import org.junit.Test

import org.junit.Assert.*
import java.util.concurrent.locks.ReentrantLock

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {

    // 任务锁
    private val taskLock = ReentrantLock()

    // 导航锁
    private val taskNavCondition = taskLock.newCondition()
    @Test
    fun addition_isCorrect() {
        for (i in 0..1000){
            var isNavRequestSuccess: Boolean = false
            GlobalScope.launch(Dispatchers.IO) {
                delay(1)
                isNavRequestSuccess=true
                System.out.println("inside$isNavRequestSuccess  $i")
            }
            try {
                taskLock.lock()
                System.out.println("等待导航完成")
                taskNavCondition.await()
            } catch (e: Exception) {
                e.printStackTrace()
            } finally {
                taskLock.unlock()
            }
            System.out.println("outside$isNavRequestSuccess  $i")
        }
    }


}